﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Serialization;
using System.Xml;
using System.IO;
using System.Timers;
using DLL.Entities;
using DLL;

namespace MIS
{
    public partial class Form1 : Form
    {
        Missile[] Missiles = new Missile[5];
        
        MIS_Config1 info = new MIS_Config1();

        public Form1()
        {

            {
                InitializeComponent();


                TextReader reader = null;

                try
                {
                    reader = new StreamReader("../../../DLL/XML/MIS_config.xml");
                    XmlSerializer serializer = new XmlSerializer(typeof(MIS_Config1));
                    info = (MIS_Config1)serializer.Deserialize(reader);
                    reader.Close();
                    txtModel.Text = Convert.ToString(info.Model);
                    txtVersion.Text = Convert.ToString(info.Version);
                    txtStatus.Text = Convert.ToString(info.MISStatus);
                }

                catch (XmlException xe)
                {
                    MessageBox.Show(xe.Message, "XML Parse Error",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
      
        private void timer1_Tick_1(object sender, EventArgs e)
        {
            info.MISStatus = Convert.ToString(DateTime.Now);

            XmlSerializer serializer = new XmlSerializer(typeof(MIS_Config1)); //You can replace Bogey with any type you are trying to serialize 
            XMLHandler.WriteXML(info, "../../../RAD/XML/Config.xml", serializer); //You can replace "Bogey_Serialzed.xml" with the file name needed
        }

        private void cBoxMissileChoice_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            txtName.Text = Missiles[cBoxMissileChoice.SelectedIndex].MissileName;
            txtRemaining.Text = Convert.ToString(Missiles[cBoxMissileChoice.SelectedIndex].MissileRemaining);
            txtRange.Text = Convert.ToString(Missiles[cBoxMissileChoice.SelectedIndex].MissileRange);
            txtSpeed.Text = Convert.ToString(Missiles[cBoxMissileChoice.SelectedIndex].MissileSpeed);
            txtWeight.Text = Convert.ToString(Missiles[cBoxMissileChoice.SelectedIndex].MissileWeight);
        }
    }
}